package cn.handong.tool.Java文件操作.excel;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping(path = "/medalDistribution")
public class MedalDistributionController {
    @Autowired
    private MedalDistributionService medalDistributionService;

    //excel文档导出
    @GetMapping("/detail/export") public void downloadMedalDetailList(HttpServletResponse response) throws IOException {
//        MedalDetailListDownloadReqPo reqPo = BeanMapper.map(request, MedalDetailListDownloadReqPo.class);
        HSSFWorkbook workbook = medalDistributionService.downloadMedalDetailList();

        //设置要导出的文件的名字
        String fileName = "MedalDetailList.xls";
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        try {
            response.flushBuffer();
            workbook.write(response.getOutputStream());
        } catch (IOException e) {
            throw e;
        }
    }
}
